#ifndef PROTOCOL_H
#define PROTOCOL_H

#include <stdint.h>
#include <stddef.h>

#define MIN_PACKET_LEN  8

// 打包：返回帧长度，<0 表示失败
int build_packet(
    uint16_t msgType,
    const uint8_t *data,
    uint16_t dataLen,
    uint8_t *buf,
    size_t buf_size
);

// 解包：返回帧总长度，<0 表示各种错误码
int parse_packet(
    uint16_t *msgType,
    uint8_t  *data,
    uint16_t *dataLen,
    const uint8_t *buf,
    size_t    buf_size
);

#endif // PROTOCOL_H
